package org.liquidByte.trafficMustang.androidApp.services;

import org.liquidByte.trafficMustang.androidApp.services.dto.LocalizacaoDTO;
import org.liquidByte.trafficMustang.androidApp.services.proxy.*;

import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;

public class Services {
	private static boolean loggedOn;

	public static boolean isLoggedOn() {
		return loggedOn;
	}
	public static void setLoggedOn(boolean loggedOn) {
		Services.loggedOn = loggedOn;
	}
	public static void cleanUp() {
		Services.loggedOn = false;
	}

	public static AvaliacaoService avaliacao() {
		return new AvaliacaoProxy();
	}
	public static LoginService login() {
		return new LoginProxy();
	}
	public static TrechoService trecho() {
		return new TrechoProxy();
	}
	public static MainService main() {
		return new MainProxy();
	}
	public static RastreamentoService rastreamento() {
		return new RastreamentoProxy();
	}
	public static VeiculoService veiculo() {
		return new VeiculoProxy();
	}
	public static DeslocamentoService deslocamento() {
		return new DeslocamentoProxy();
	}

	public static LocationListener getLocationListener() {
		return new LocationListener() {
			@Override
			public void onStatusChanged(String provider, int status, Bundle extras) { }
			@Override
			public void onProviderEnabled(String provider) { }
			@Override
			public void onProviderDisabled(String provider) { }
			@Override
			public void onLocationChanged(Location location) {
				RastreamentoService service = Services.rastreamento();
				try {
					service.update(LocalizacaoDTO.fromLocation(location));
				} catch (Exception e) { }
			}
		};
	}
}
